package com.sparkseries.service.impl;

import com.sparkseries.common.util.domain.Result;
import com.sparkseries.service.LogoutService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 退出登录
 */
@Service
@Slf4j
public class LogoutServiceImpl implements LogoutService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 退出
     * @param token 用户Token
     * @return 默认响应类
     */
    @Override
    public Result<?> logout(String token) {
        String redisToken = stringRedisTemplate.opsForValue().get("loginToken:" + token);

        if (Objects.nonNull(redisToken)) {
            log.info("退出登录失败");
            return Result.error("退出登录失败");
        }
        return Result.ok("退出登录成功 ");
    }
}
